package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteChapterOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocChapterDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocChapterCommand;
import com.cskaoyan.wordmemorize.request.VocChapterPageRequest;
import com.cskaoyan.wordmemorize.service.VocChapterService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/voc")
public class VocChapterController {

    @Resource
    VocChapterService vocChapterService;

    /**
     * 修改章节(后端-物料管理-章节管理)
     *
     * @param command 章节请求体
     * @return 空结果
     */
    @PutMapping("chapter")
    public Result<Void> UpdateChapter(@RequestBody VocChapterCommand command) {
        vocChapterService.updateChapter(command);
        return Result.ok();

    }

    /**
     * 添加章节(后端-物料管理-章节管理)
     *
     * @param command 章节请求体
     * @return 空结果
     */
    @PostMapping("chapter")
    public Result<Void> addChapter(@RequestBody VocChapterCommand command) {
        vocChapterService.addChapter(command);
        return Result.ok();

    }

    /**
     * 分页查询章节列表(后端-物料管理-章节管理)
     *
     * @param pageQuery 分页查询请求体
     * @return 章节列表
     */
    @GetMapping("chapters/list")
    public Result<PageDTO<VocChapterDTO>> getVocChapterList(VocChapterPageRequest pageQuery) {
        PageDTO<VocChapterDTO> chapterPage = vocChapterService.getChapterPage(pageQuery);
        return Result.ok(chapterPage);

    }

    /**
     * 删除章节(后端-物料管理-章节管理)
     *
     * @param chapterId 章节ID
     * @return DeleteChapterOperateDTO 删除章节操作日志
     */
    @DeleteMapping("chapter/{chapterId}")
    public Result<DeleteChapterOperateDTO> deleteChapter(@PathVariable Long chapterId) {
        DeleteChapterOperateDTO operateDTO = vocChapterService.deleteChapter(chapterId);
        return Result.ok(operateDTO);

    }

    /**
     * 批量删除选中章节(后端-物料管理-章节管理)
     *
     * @param ids 章节ID列表
     * @return DeleteChapterOperateDTO 删除章节操作日志列表
     */
    @DeleteMapping("chapters")
    public Result<List<DeleteChapterOperateDTO>> deleteChapters(@RequestBody BatchDeleteCommand ids) {
        List<DeleteChapterOperateDTO> operateDTOList = vocChapterService.deleteChapters(ids);
        return Result.ok(operateDTOList);
    }
}
